package com.lims.数据库;

/**
 * @author limaosheng
 * @create 2023-10-23 11:24
 * @desc
 */
public class 数据库表创建sql {
    public static void main(String[] args) {
        String tableComment = "存量图片上传失败记录表";
        String tableName = "ec_image_fail";
        String index = "";
        String indexComment = "";
        String str = "id" +
                "\tint" +
                "\t11" +
                "\t是" +
                "\t自增主键" +
                "\n" +
                "route_md5url" +
                "\tvarchar" +
                "\t256" +
                "\t是" +
                "\t图片地址" +
                "\n" +
                "fail_msg" +
                "\tvarchar" +
                "\t256" +
                "\t是" +
                "\t失败原因描述：下载原图片失败，人脸图片小于10k，人脸图片大于1M，人脸图片检测不通过（原因）、图片上传失败" +
                "\n" +
                "entity_id" +
                "\tbigint" +
                "\t20" +
                "\t是" +
                "\t对应使用图片的实体表ID，当前支持员工、居民" +
                "\n" +
                "type" +
                "\tint" +
                "\t2" +
                "\t是" +
                "\t图片类型：1-员工人脸，2-居民人脸，3-居民身份证正面，4-居民身份证反面" +
                "\n" +
                "gmt_create" +
                "\tdatetime" +
                "\t0" +
                "\t是" +
                "\t创建时间" +
                "\n" +
                "gmt_modified" +
                "\tdatetime" +
                "\t0" +
                "\t是" +
                "\t修改时间" +
                "\n";

        StringBuilder sb = new StringBuilder();
        sb.append("create table " + tableName + "\n");
        sb.append("(\n");
        String[] arr = str.split("\n");
        for(String s : arr){
            String[] sArr = s.split("\t");
            String col = sArr[0];
            String type = sArr[1];
            String length = sArr[2];
            String notNull = sArr[3];
            String comment = sArr[4];
            if(col.equals("id")){
                sb.append("    id           int auto_increment,\n");
            }else{
                if(type.equals("datetime") || type.equals("date")){
                    if(notNull.equals("是")){
                        sb.append("    "+col+" "+type+"     not null comment '"+comment+"',\n");
                    }else {
                        sb.append("    "+col+" "+type+"     comment '"+comment+"',\n");
                    }
                }else {
                    if(notNull.equals("是")){
                        sb.append("    "+col+" "+type+"("+length+") not null comment '"+comment+"',\n");
                    }else {
                        sb.append("    "+col+" "+type+"("+length+") comment '"+comment+"',\n");
                    }
                }
            }
        }
        sb.append("    constraint "+tableName+"_pk primary key (id)\n");
        sb.append(")\n");
        sb.append("comment '"+tableComment+"' charset = utf8mb4;\n");
        if(!index.equals("")){
            sb.append("create unique index idx_"+index+"\n");
            sb.append("    on "+tableName+" ("+index+")\n");
            sb.append("    comment '"+indexComment+"';\n");
        }
        System.out.println(sb.toString());
    }

}
